function detect_browser() {
	return navigator.userAgent.indexOf('MSIE')>0?true:false;
}
function text_OnKeyPress_NumberOnlyAndDot() {
    var keyAble = false;
    try {
        key = window.event.keyCode;
       if ( (key == 46) || (key > 47 && key < 58) )
          keyAble = true; // if so, do nothing
       else
          keyAble = false;
     } catch(err) {
        throw new Error(" error in sub text_OnKeyPress_NumberOnlyAndDot function() cause = " + err.message);
    } 
    return keyAble;
}

function text_OnKeyPress_NumberOnly() {
     var keyAble = false;
     try {   
       key = window.event.keyCode;
       if ( key > 47 && key < 58)
          keyAble = true; // if so, do nothing
       else
          keyAble = false;
    } catch(err) {
        throw new Error(" error in sub text_OnKeyPress_NumberOnly function() cause = " + err.message);
    } 
    return keyAble;
}
function validateDateFormat(textObj) {
	try {
		var valDate = textObj.value;
		if (valDate != "") {
			var count = 0;
			var size = valDate.length;
			for ( var i = 0; i < size; i++) {
				if (valDate.substr(i, 1) == "/")
					count++;
			}
			var strDay = "", strMonth = "", strYear = "";
			if (count == 0) {
				strDay = valDate.substr(0, 2);
				strMonth = valDate.substr(2, 2);
				strYear = valDate.substr(4, 4);
			} else if (count == 2) {
				dateArray = valDate.split("/");
				strDay = dateArray[0];
				strMonth = dateArray[1];
				strYear = dateArray[2];
			} else {
				// in case "/"
			}
			if (strDay.length < 2)
				strDay = "0" + strDay;
			if (strMonth.length < 2)
				strMonth = "0" + strMonth;
			if ((strYear.length < 4) || (strYear.length > 4)) {
				goError(textObj);
				return;
			} else if (parseInt(strYear) > 2643 || parseInt(strYear) < 1900) {
				textObj.value = '';
				textObj.focus();
				return;
			} else if (parseInt(strYear) > 2100) {
				//---- check year by suree ---------------
				strYear = parseInt(strYear) - 543;
			}
			// Reformat the date for validation
			var strSeperator = "/";
			var vDateValueCheck = strMonth + strSeperator + strDay
					+ strSeperator + strYear;
			if (!dateValid(vDateValueCheck)) {
				goError(textObj);
				return;
			}
			textObj.value = strDay + "/" + strMonth + "/" + strYear;
			return true;
		}
	} catch (err) {
		throw new Error(
				" error in sub validateDateFormat function() cause = "
						+ err.message);
	}
}
function calculateBetweenDate(startDate,endDate){
    try {
		var date1 		= startDate.substring(0,2);
		var month1 		= startDate.substring(3,5);
		var year1 		= startDate.substring(6,10);
		var date2 		= endDate.substring(0,2);
		var month2 		= endDate.substring(3,5);
		var year2 		= endDate.substring(6,10);
		var t1 			= Date.UTC(parseInt(year1), parseInt(month1, 10)-1, parseInt(date1, 10));
		var t2 			= Date.UTC(parseInt(year2), parseInt(month2, 10)-1, parseInt(date2, 10));
		var diffDate 	= t2-t1;
		
		var minutes 	= 1000*60;
		var hours 		= minutes*60;
		var days 		= hours*24;
		
		var result		= diffDate/days;
		
		return result;
    } catch(err) {
    	throw new Error(" error in sub calculateBetweenDate function() cause = " + err.message);
    } 
}
function showPopup(url, id, height, width) {

    var popupHeight = height;
    var popupWidth = width;

    var posX = parseInt((window.screen.availWidth - popupWidth) / 2);
    var posY = parseInt((window.screen.availHeight - popupHeight) / 2);

    if (posX < 0) { posX = 0; }
    if (posY < 0) { posY = 0; }

    var popup = window.open(url, id, "location=no,menubar=no,resizable=no,status=yes,toolbar=no,width="+ popupWidth +",height="+ popupHeight+",scrollbars=no,left=" + posX + ",top=" + posY , "true");                
    tmp_popup = popup;
    return popup;
}
function showModalDialogPopup(url, height, width) {

    var popupHeight = height;
    var popupWidth = width;

    var posX = parseInt((window.screen.availWidth - popupWidth) / 2);
    var posY = parseInt((window.screen.availHeight - popupHeight) / 2);

    if (posX < 0) { posX = 0; }
    if (posY < 0) { posY = 0; }

    var popup = window.showModalDialog(url, "", "resizable=no,status=yes,dialogWidth="+ popupWidth +",dialogHeight="+ popupHeight+",center=yes,dialogLeft=" + posX + ",dialogTop=" + posY , "true");                
    tmp_popup = popup;
    return popup;
}

function removeCommas( valueStr ) {
    try {
      if(valueStr == "undefined" || valueStr == null) {
         valueStr = "";
      }
      if(typeof valueStr == 'number') valueStr += "";

      var objRegExp = /,/g; //search for commas globally
      return valueStr.replace(objRegExp,'');
   } catch(err) {
        throw new Error(" error in sub removeCommas function() cause = " + err.message);
    } 
}
function getJSONResult(resultParam){
    if(typeof resultParam == "undefined") {
        return "";
    } else {
        return resultParam;
    }
}
function tryNumberFormatValue(value, iscomma, decnum){
    try {
        if(typeof value == 'number') value += "";
	if(value != ""){
		var nf = new NumberFormat(value);
		nf.setPlaces(decnum);
		nf.setSeparators(iscomma);
		value = nf.toFormatted();
	}
	return value;
      } catch(err) {
        throw new Error(" error in sub tryNumberFormatValue function() cause = " + err.message);
     } 
}